#include<iostream>

using namespace std;

const int N = 110;
string arr_up[N], arr_down[N], arr_same[N];

int main()
{
	int n; cin >> n; int up = 0, down = 0,x=0,y=0; 
	for (int i = 0; i < n; i++) {
		string s1, s2;
		cin >> s1;        
		cin >> s2;         
		if (s2 == "UP") arr_up[up++] = s1;
		if (s2 == "DOWN") arr_down[down++] = s1;
		if (s2 == "SAME") arr_same[i] = s1;
	}
	for (int i = 0; i < n; i++)
	{
		if (arr_same[i] != "") continue;
		else
		{
			if (x<down) arr_same[i] = arr_down[x++];
			else  arr_same[i] = arr_up[y++];
		}
	}
	for (int i = 0; i<n; i++)  cout << arr_same[i] << endl;

	return 0;
}

